package com.yy.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yy.entity.front.AddressBook;
import com.yy.service.front.AddressBookService;
import com.yy.service.front.UserService;
import com.yy.utils.BaseContext;
import com.yy.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * create by KongFuning on 2022/8/4
 */
@RestController
@RequestMapping("/addressBook")
@Slf4j
public class AddressBookController {

    @Autowired
    private AddressBookService addressBookService;

    /*
    * 添加地址信息
    * */
    @PostMapping
    public R saveAddressBook(@RequestBody AddressBook addressBook){
        return addressBookService.saveAddressBook(addressBook);
    }

    /*
    * 查询指定用户的全部地址
    * */
    @GetMapping("/list")
    public R listAddressBook(AddressBook addressBook){
        return addressBookService.listAddressBook(addressBook);
    }

    /*
    * 设置默认地址
    * */
    @PutMapping("/default")
    public R defaultAddress(@RequestBody AddressBook addressBook){
        return addressBookService.defaultAddress(addressBook);
    }

    /*
     * 查询默认地址
     * */
    @GetMapping("/default")
    public R getDefaultAddress(){
        return addressBookService.getDefaultAddress();
    }

    /*
    * 编辑收货地址 回显数据
    * */
    @GetMapping("/{id}")
    public R toUpdateAddress(@PathVariable String id){
        return addressBookService.toUpdateAddress(id);
    }

    /*
     * 保存收货地址
     * */
    @PutMapping
    public R updateAddress(@RequestBody AddressBook addressBook){
        return addressBookService.updateAddress(addressBook);

    }
}
